package com.ymatou.iapi.fundcommission.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.fundcommission.service.BackCommissionRateGetCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.YmtFundDimensionWapper;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.YMTDateUtil;
/**
*退佣费率查询接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BackCommissionRateGet{
	private static BackCommissionRateGetCall backcommissionrategetCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退佣费率查询接口");
	}

	@Before
	public void caseUp() {
		backcommissionrategetCall=new BackCommissionRateGetCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(backcommissionrategetCall.getOpurl());
	}

	/**
	 * chargecommissionrateget接口返回信息公用错误信息部分断言（正向Case场景）
	 * @throws Exception
	 */	
	public static void backCommissionRateGetreturncode() throws Exception {
	    try {	    	
			//获取返回报文的数据
			String dataStr = backcommissionrategetCall.getReturnData();
			//返回报文断言
			Logger.verifyNotNull(dataStr, "返回报文非空");			
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(true, Success, "\"Success\":true");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "Msg等于空");
			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsNull(errCode, "ErrCode等于空");
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body等于空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl等于空");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  

	}
	
	/**
	 * 错误信息断言
	 * @param errcode 错误代码
	 * @param eMsg 错误信息
	 * @throws Exception
	 */
	public void  backCommissionRateGetreturnerrcode(String ecode,String eMsg) throws Exception {
	    try {
	    	
			//获取返回报文的数据
			String dataStr = backcommissionrategetCall.getReturnData();
			//返回报文断言			
			String productCommissionList =  new JSONObject(dataStr).getString("ProductBackCommissionList");
			Logger.verifyIsNull(productCommissionList, "ProductCommissionList为空");
			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsContains(ecode, errCode, "ErrCode");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsContains(eMsg, errMsg, eMsg);
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body为空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl为空");
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(false, Success, "\"Success\":false");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  
	}
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_001() {
		Logger.start(true,"退佣费率查询");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "100");			//订单价格
			aa.put("ProductInfoList[0]->CategoryId", "423425236");		//商品类目id
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturncode();
			
			String dataStr = backcommissionrategetCall.getReturnData();
			//ymt_fundstrategy inner join ymt_fundstrategydimension
			YmtFundDimensionWapper ymtFundDimensionWapper = new YmtFundDimensionWapper();	    	
	        List<Map> fundstdi = ymtFundDimensionWapper.selectstrategybystrategytype("2");
			String stid=(String) fundstdi.get(0).get("StrategyId");
			Logger.verifyEquals(stid,  new JSONObject(dataStr).getJSONArray("ProductBackCommissionList").getJSONObject(0).getString("StrategyId"), "策略Id对比");
			BigDecimal stAmount= (BigDecimal) fundstdi.get(0).get("StrategyAmount"); //数据库查询结果
			double backCommissionRate=new JSONObject(dataStr).getJSONArray("ProductBackCommissionList").getJSONObject(0).getDouble("BackCommissionRate"); //返回报文结果
			Logger.verifyEquals(stAmount,  new BigDecimal(backCommissionRate).setScale(2,BigDecimal.ROUND_HALF_UP), "策略费率对比");				
			String strategyLevelType = new JSONObject(dataStr).getJSONArray("ProductBackCommissionList").getJSONObject(0).getString("StrategyLevelType");
			Logger.verifyIsContains(2, strategyLevelType, "策略级别对比");
			String remark=(String) fundstdi.get(0).get("Remark");
			String remarkbyRateGet = new JSONObject(dataStr).getJSONArray("ProductBackCommissionList").getJSONObject(0).getString("Remark");
			Logger.verifyIsContains(remark, remarkbyRateGet, "策略备注对比");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_002() {
		Logger.start(false,"订单号不能为空");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", null);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "100");			//订单价格
			aa.put("ProductInfoList[0]->CategoryId", "423425236");		//商品类目id
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1001", "订单号不能为空！");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_003() {
		Logger.start(false,"退货退款时间不能为空");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", null);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "100");			//订单价格
			aa.put("ProductInfoList[0]->CategoryId", "423425236");		//商品类目id
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1002", "退货退款时间不能为空!");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_004() {
		Logger.start(false,"商品信息集合不能为空");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList", null);			
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1005", "商品信息集合不能为空!");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_005() {
		Logger.start(false,"商品类目不能为空");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "100");			//订单价格
			aa.put("ProductInfoList[0]->CategoryId", null);		//商品类目id
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1101", "商品类目不能为空!");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_006() {
		Logger.start(false,"商品卖价不能小于0");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "-1");			//订单价格
			aa.put("ProductInfoList[0]->CategoryId", "456564");		//商品类目id
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1104", "商品卖价不能小于0!");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_007() {
		Logger.start(false,"商品Id不能为空");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "100");			//订单价格
			aa.put("ProductInfoList[0]->ProductId", null);		
			aa.put("ProductInfoList[0]->CategoryId", "456564");		//商品类目id
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1106", "商品Id不能为空!");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_008() {
		Logger.start(false,"商品买家信息不能为空");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "100");			//订单价格
			aa.put("ProductInfoList[0]->CategoryId", "456564");		//商品类目id
			aa.put("BuyerId", null);		//买家id
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1108", "商品买家卖家信息不能为空！");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_009() {
		Logger.start(false,"商品卖家信息不能为空");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "100");			//订单价格
			aa.put("ProductInfoList[0]->CategoryId", "456564");		//商品类目id
			aa.put("SellerId", null);		//买家id
			aa.put("CountryId", "423423");		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1108", "商品买家卖家信息不能为空！");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BackCommissionRateGet_010() {
		Logger.start(false,"卖家所在国家Id不能为空");
		try {
			//TODO 补全case代码
			//修改backCommissionRateGet接口参数
			int num1 = (int)(Math.random()*1000000000);
			String orderBackDate = YMTDateUtil.getBeforeOrNextDay(0);
			Map<String,Object> aa = new HashMap<String, Object>();
			aa.put("OrderId", num1);		//订单id 如果订单重复，会返回第一次查询结果的缓存
			aa.put("OrderBackDate", orderBackDate);			//业务发生日期
			aa.put("ProductInfoList[0]->ProductPrice", "100");			//订单价格
			aa.put("ProductInfoList[0]->CategoryId", "456564");		//商品类目id
			aa.put("CountryId", null);		//国家id
			//调用接口json文件
			JSONObject backcommissionrategetBean =  JsonBeanHelper.getJsonBean("/com.ymatou.iapi.fundcommission/BackCommissionRateGet.json");
			backcommissionrategetBean = JsonBeanHelper.updateJsonBean(backcommissionrategetBean, aa);
			
			backcommissionrategetCall.setData(backcommissionrategetBean);
			backcommissionrategetCall.callService();
			backCommissionRateGetreturnerrcode("1109", "卖家所在国家Id不能为空!");
					
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}